<?php
/**
 * 团购
 * User: E 房cms www.fangcms.com
 * Date: 2015/1/20
 * Time: 10:51
 */
namespace Home\Controller;
use Org\Util\Page;
use Org\Yike\FangCms;
class BuyingController extends CommonController{
    public function _initialize(){
        parent::_initialize();
        $this->group_set = _setting('group',1);
        $qq_qun = array();
        $qq_arr = explode(',',$this->group_set['group_qq_qun']);
        foreach($qq_arr as $v){
            $q = explode('|',$v);
            $qq_qun[] = array('name'=>$q[0],'qq'=>$q[1]);
        }
        $this->qq_qun = $qq_qun;
        //推荐楼盘
        $this->rec_house =  M('house')->where(array('is_rec'=>1,'status'=>1))->order('ordid desc')->limit(8)->select();
    }

    public function index(){
        $where = array('status'=>1,'end_time'=>array('gt',time()));
        $type = I('get.type','0');
        if($type){
            $where['end_time'] = array('lt',time());
            $this->type = $type;
        }
        $alias = I('get.alias','');
        if($alias){
            $cate = M('house_cate')->where(array('alias'=>$alias,'pid'=>0))->find();
            if($cate){
                $where['area_id'] = $cate['id'];
                $this->alias = $alias;
            }else{
                $this->error('找不到对应的团购分类信息',U('Buying/index'));
            }
        }

        $count = M('group')->where($where)->count();
        $pager = new Page($count, 8);
        $this->list = M('group')->where($where)->limit($pager->firstRow.','.$pager->listRows)->order('id desc')->select();
        $this->page = $pager->show();
        $this->house_cate = M('house_cate')->where(array('status'=>1,'pid'=>0))->order('ordid desc')->select();
        $this->display();
    }

    //问答详细
    public function detail(){
        $id = intval($_GET['id']);
        if(!$id){
            $this->error('没有找到对应ID信息');
        }
        $info = M('group')->where(array('id'=>$id,'status'=>1))->find();
        if(!$info['id']){
            $this->error('没有找到对应ID信息');
        }
        $FangCms = new FangCms();
        $FangCms->setInc($id,'group');
        //相关楼盘
        if($info['house_id']){
            $house = M('house')->where(array('id'=>$info['house_id'],'status'=>1))->find();
            $this->address = explode('|',$house['address']);
            $this->house_tags = explode('|',trim($house['tags'],'|'));
            $this->menu = getLinkMenuFor(array('6'));
            $this->house = $house;
        }

        if($info['file']){
            $file = json_decode($info['file'],true);
            if(!empty($file) && is_array($file)){
                $this->img_list = $file;
            }
        }

        $this->tags = $info['tags'] ? explode(',',$info['tags']) : '';
        $this->info = $info;
        $this->seoKey($info,'title');
        $this->display();
    }




}